

local ItemTool=_G.CommonOHOH.load.ItemTool();

local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),script.Parent.Name);
local CallBackManager = ClientOHOH.load.CallBackManager();
local InstanceManager = ClientOHOH.load.InstanceManager();
local Client_AudioManager = ClientOHOH.load.Client_AudioManager();
local FavoriteReward=ClientOHOH.config.Activity[4].arg

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

    self.DataBase=self.parent:GetComponent(ClientOHOH.load.Client_PlayerDataComponent());
    self.Favorite= ClientOHOH:GetPath_Loop("AddFavorite",game.Workspace)
    local Image= ClientOHOH:GetPath_Loop("Ctrl.icon", self.Favorite).Value
    local CountLable= ClientOHOH:GetPath_Loop("Ctrl.count", self.Favorite).Value

    for k,v in pairs(FavoriteReward) do
        Image.Image=_G.CommonOHOH.load.ItemTool().GetItemShowView(k)
        CountLable.Text="x"..v
    end

    if  self.DataBase:GetData("favorite") then
        self:HideFavorite()
    else
        local touch= ClientOHOH:GetPath_Loop("Touch",self.Favorite)

        CallBackManager:AddRbxConnect(self,touch.Touched, function(obj,chPart)

            if not _G.CommonOHOH.load.GeneralTool().IsMeTouchEvent(chPart,"LeftLowerLeg") then
                return 
            end
            if self:isCdOver() then
                self:AddProcess(function()
                    self:AddFavorite()
                    self:Wait(8) --五秒后认为收藏成功
                    self:RewardByFavorite()
                end)
            end

        end);
        
    end
 
 


end;

function M.isCdOver(self)
    if not self.lastTime then
        self.lastTime=os.time()
        return true
    end

    if os.time()-self.lastTime>5 then
        self.lastTime=os.time()
        return true
    end
    return false
end



function M.AddFavorite(self)
    game:GetService("AvatarEditorService"):PromptSetFavorite(game.PlaceId, Enum.AvatarItemType.Asset, true)
end

local FunctionList = ClientOHOH.load.FunctionList();

function M.RewardByFavorite(self)
    if self:Invoke(FunctionList.favorite_game) then
        self:ShowReward()
        self:HideFavorite()
    end
end


function M.ShowReward(self)
    local LanguageHelper=_G.LanguageHelper 
    for k,v in pairs(FavoriteReward) do
        ClientOHOH.load.UIManager().ui_list.GlobalTipGui:Show(LanguageHelper:GetText(560001))
        ItemTool.FlyingItem(k,v)
        Client_AudioManager:PlayGloble("claim");
    end
end

function M.HideFavorite(self)
    self.Favorite.Parent=nil

end

function M.dtor(self)
	M.super.dtor(self);
end;

return M
